package com.wanxi.servlet.suggest;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.SuggestModel;
import com.wanxi.service.Impl.SuggestServiceImpl;
import com.wanxi.service.SuggestService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/5 20:12
 */
@WebServlet("/back/DeleteSuggest")
public class DeleteSuggestServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.获取前端数据
        String id = req.getParameter("id");
        //3.封装model
        SuggestModel suggestModel= SuggestModel.builder()
                .id(Tool.strToInt(id))
                .build();
        //4.调用service层
        SuggestService suggestService = new SuggestServiceImpl();
        ResultDto resultDto = suggestService.delete(suggestModel);
        //5.返回前台数据
        resp.getWriter().println(JSONObject.toJSONString(resultDto));
    }
}
